package com.algorithm.ch1.yjx.array;

import java.util.Arrays;

/**
 * @author yuanjianxin
 * @date 2018/8/13 18:12
 */
public class ContainsDuplicate {

    public static void main(String[] args) {

        int[] nums = {1, 5,4,5};
        System.out.println(containsDuplicate(nums));
        System.out.println(containsDuplicate1(nums));
    }

    public static boolean containsDuplicate(int[] nums) {
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] == nums[j]) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean containsDuplicate1(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                return true;
            }
        }
        return false;
    }

}
